/**
 *	\file
 *	\brief represents a cell inside an hash table designed for containing labels.
 *
 * 	\date Sep 13, 2013
 * 	\author koldar
 *	\version 1.0
 */

#ifndef LABELHTCELL_H_
#define LABELHTCELL_H_

#include "Label.h"
#include "uthash.h"

/**indicates an element of an hash table storing labels
 *
 */
typedef struct LabelHTCell {
	const char* key; //!< indicates the key of the value inside this hashtable
	Plabel label; //!< indicates the value associated to the key
	UT_hash_handle hh;
} LabelHTCell;

/**ca be interpreted as:
 * \li pointer of a single cell of the hash table;
 * \li an entire hash table
 *
 */
typedef LabelHTCell* PlabelHTCell;


/**initialize correctly an hashtable cell. It can be freed with freeLabelHT()
 *
 * 	\pre
 * 	 \li label not NULL;
 * 	\post
 * 	 \li an element of the hash table that can be added to the hash table
 * 	 \li the element just added has key equal to the field "name" of the label _label
 *
 * @param _label the object to prepare to store data
 * @return a pointer to the newly created Label
 */
PlabelHTCell initLabelHTCell(Plabel _label);

/**deallocates a cell of the hash table
 *
 * \pre
 *  \li pcell must not be NULL
 *
 * @param pcell the object to deallocates
 */
void freeLabelHTCell(PlabelHTCell pcell);

/**prints a string representation of this hash table cell
 *
 * \pre
 *  \li f open in write mode
 *  \li pcell not NULL
 * \post
 *  \li f changed permanently
 *
 * @param f the file to write the string on
 * @param pcell the cell to be printed
 */
void printLabelHTCell(FILE* f,PlabelHTCell pcell);

/**writes in f a code block that can be interpreted as a node in DOT language.
 * This function should be used to automatically generate DOT file representing hash tables
 *
 * \pre
 *  \li f open in write mode;
 * \post
 *  \li in f there is a piece of code <b>not</b> directly compilable by dot;
 *  \li in f there is a piece of code representing this cell;
 *
 * @param f the file to write on
 * @param pcell the cell of the hash table which has to be drawn
 * @param nodenumber the number of the dot node identifier. For example if you pass 53 then the ID will be n053. The regex is n%03d
 */
void generateDOTLabelHTCell(FILE* f,PlabelHTCell pcell,int nodenumber);


#endif /* LABELHTCELL_H_ */
